import { createRouter, createWebHistory ,createWebHashHistory} from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect:'/login',
      component: () => import('../views/longin/index.vue')
    },
    {
      path: '/home',
      name: 'home',
      component: () => import('../views/home/index.vue')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/longin/index.vue')
    },
    {
      path: '/dn',
      name: 'diannao',
      component: () => import('../views/home/dn.vue')
    },
    {
      path: '/qt',
      name: 'qita',
      redirect:'/qt/qitaIndex/0',
      component: () => import('../views/home/qt.vue'),
      children:[
        {
          path: 'qitaIndex/:num',
          name: 'qitaIndex',
          component: () => import('../views/qita/index.vue')
        },
      ]
    },
    {
      path: '/mine',
      name: 'mine',
      component: () => import('../views/home/mine.vue')
    },
    {
      path: '/vivi',
      name: 'sp',
      component: () => import('../views/shengpi/index.vue')
    },
    {
      path: '/adduser',
      name: 'adduser',
      component: () => import('../views/home/adduser.vue')
    },
    {
      path: '/mmjc',
      name: 'mmjc',
      component: () => import('../views/mmjc/index.vue')
    },
  ]
})
//防跳墙
router.beforeEach((to, from) => {
  if (to.fullPath === "/login") {
    if (localStorage.getItem("userinfo")) {
      return { path: "/home" };
    }
    return true;
  } else if (localStorage.getItem("userinfo")) {
    return true;
  } else {
    return { path: "/login" };
  }
});
export default router
